package demo.practice.leetcode_eveyday;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

class Employee {
    public int id;
    public int importance;
    public List<Integer> subordinates;
};

public class P690 {
    Map<Integer ,Employee> map= new HashMap<>();
    public int getImportance(List<Employee> employees, int id) {
        for (Employee employee : employees) {
            map.put(employee.id,employee);
        }
        return getValue(map.get(id));
    }

    private int getValue(Employee employee){
        int sum=0;
        if(employee!=null){
            sum+=employee.importance;
            for (Integer subid : employee.subordinates) {

                Employee sub=   map.get(subid);
                sum+=getValue(sub);
            }
        }
        return sum;
    }
}
